package com.smart.integral.listener;

import com.smart.common.constants.MessageConstants;
import com.smart.common.dto.integral.IntegralDto;
import com.smart.integral.entity.Integral;
import com.smart.integral.mapper.IntegralMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

/**
 * 积分监听
 *
 * @author zhangwei
 */

@RocketMQMessageListener(consumerGroup = MessageConstants.MQ_INTEGRAL_GROUP,
        topic = MessageConstants.MEMBER_INTEGRAL_TOPIC)
public class IntegralListener implements RocketMQListener<IntegralDto> {
    @Resource
    IntegralMapper integralMapper;

    @Override
    public void onMessage(IntegralDto message) {
        Integral integral = new Integral();
        BeanUtils.copyProperties(message, integral);
        integralMapper.insert(integral);
    }
}
